using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Diagnostics;

namespace MaskData
{
	public abstract class ElementType
	{
		protected readonly String _fieldName;

		public String FieldName
		{
			get {
				return _fieldName;
			}
		}
		protected readonly String _fieldCaption;
		public String Caption
		{
			get {
				return _fieldCaption;
			}
		}
		protected readonly bool _IsKey;
		public bool IsKey
		{
			get {
				return _IsKey;
			}
		}

		protected readonly bool _IsDisplay;
		public bool IsDisplay
		{
			get {
				return _IsDisplay;
			}
		}

		protected readonly Int32 _Order;
		public Int32 Order
		{ 
			get {
				return _Order;
			}
		}

		public ElementType(String fieldName, String fieldCaption,bool isKey, bool display, Int32 order)
		{
			_fieldName = fieldName;
			_fieldCaption = fieldCaption;
			_IsKey = isKey;
			_Order = order;
			_IsDisplay = display;
		}
		public abstract Type GetColumn();
		public DataColumn ToColumn()
		{
			DataColumn column = new DataColumn();
			column.ColumnName = _fieldName;
			column.Caption = _fieldCaption;
			column.DataType = GetColumn();
			column.ReadOnly = false;
			column.Unique = false;

			return column;
		}
		public abstract MaskElement CreateMaskElement(Object value);
	}

	public class StringElementType : ElementType
	{
		public StringElementType(String fieldName, String fieldCaption, bool isKey, bool display, Int32 order)
			: base(fieldName, fieldCaption, isKey, display, order)
		{ }
		public override Type GetColumn()
		{ 
			return typeof(String);
		}
		public override MaskElement CreateMaskElement(Object value)
		{
			Debug.Assert(value.GetType() == typeof(String));
			return new StringMaskElement(this, (String)value);
		}
	}


	public class IntElementType : ElementType
	{
		public IntElementType(String fieldName, String fieldCaption, bool isKey, bool display, Int32 order)
			: base(fieldName, fieldCaption, isKey, display, order)
		{ }
		public override Type GetColumn()
		{
			return typeof(Int32);
		}
		public override MaskElement CreateMaskElement(Object value)
		{
			Debug.Assert(value.GetType() == typeof(Int32));
			return new IntMaskElement(this, (Int32)value);
		}
	}
	public class BoolElementType : ElementType
	{
		public BoolElementType(String fieldName, String fieldCaption, bool isKey, bool display, Int32 order)
			: base(fieldName, fieldCaption, isKey, display, order)
		{ }
		public override Type GetColumn()
		{
			return typeof(bool);
		}
		public override MaskElement CreateMaskElement(Object value)
		{
			Debug.Assert(value.GetType() == typeof(bool));
			return new BoolMaskElement(this, (bool)value);
		}
	}
}
